'use strict';

const Service = require('egg').Service;

class userService extends Service {

  /*
  * 查询list 
  * Method: get
  * path: /xxxx
  */
  async index (query, fields, options) {
    const result = await this.ctx.model.User.find(query, fields, options).lean()
    return result
  }

  /*
  * 根据key查询
  * Method: get
  * path: /xxxx/:id
  */
  async show (query) {
    // const list = await this.app.mysql.get('user', obj)
    // return list
    const result = await this.ctx.model.User.findOne(query).lean()
    return result
  }



 /**
   * 添加用户信息
   * @param {Object ArrayObject} data 
   * @return { Object ArrayObject } return data
   */

  async create(data) {
    const result = await this.ctx.model.User.create(data)
    return result
  }

  /*
  * 修改更新
  * Method: put
  * path: /xxxx/:id
  */
  async update(query, data) {
    const result = await this.ctx.model.User.update(query, data)
    return result
  }

  /**
   * 删除符合条件的信息
   * @param {Object} query 
   */
  async destroy(query) {
    const result = await this.ctx.model.User.remove(query)
    return result
  }
}

module.exports = userService
